Loki_Configuration
Loki Configuration
Loki can be configured to collect logs from all namespaces in a Kubernetes cluster.
Set up a single Loki instance with a Promtail agent that is configured to watch all namespaces.
-
Promtail Configuration: In Promtail configuration file, specify the
kubernetes_sd_configs
to scrape logs from all namespaces. For example:scrape_configs:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: namespace -
ClusterRole and ClusterRoleBinding: Ensure Promtail has the necessary permissions to access logs from all namespaces. Create a
ClusterRole
andClusterRoleBinding
to grant these permissions:apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: promtail
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: promtail
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: promtail
subjects:
- kind: ServiceAccount
name: promtail
namespace: default -
Deploy Promtail: Deploy Promtail with the above configuration and ensure it has the necessary permissions.
By following these steps, we can configure Loki to collect logs from all namespaces without needing separate configurations for each service.